#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 105;

int n;
int a[N];
int pre[N];
int dp[N][N];

signed main() {
        freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        memset(dp, 0, sizeof(dp));
        memset(pre, 0, sizeof(pre));
        cin >> n;
        for (int i = 1; i <= n; i++)
            scanf("%lld", &a[i]);
        for (int i = 1; i <= n; i++)
            pre[i] = pre[i - 1] + ((a[i] == a[i - 1]) ? a[i] : 0);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j < i; j++) {
                dp[j][i] = ((a[i] == a[j]) ? a[i] : 0) + pre[i - 1] - pre[j];
                for (int k = 1; k < i; k++)
                    for (int p = k + 1; p < i; p++)
                        dp[j][i] = max(dp[j][i], dp[k][p] + ((a[i] == a[j]) ? a[i] : 0));
            }
        int ans = 0;
        for (int i = 1; i <= n; i++)
            ans = max(ans, dp[i][n]);
        cout << ans << '\n';
    }
    return 0;
}
/*
1
8
3 5 2 5 1 2 1 4
*/
/*
dp, segment tree, hash, kmp, maths, greedy, graph
*/
